<?php
class HomeController extends BaseController
{      
    public function _initialize() {
        parent::_initialize();
        $this->id = session('id');
    }
    //我的首页
    public  function index()
    {   
        
        $user_info = M('user')->where(['id'=>$this->id])->find();
        $sum  = M('hang_buy')->where(['user_id'=>$this->di,'status'=>['in',[1,2,3]]])->count()*100;
        if($user_info['photo'] || $user_info['alipay_account']  || $user_info['wx_qr_code']){
            if($user_info['if_complete'] != 1){
                M('user')->where(['id'=>$this->id])->setField('if_complete',1);
            }
            
        }
        $records  = M('upvaluation_put_records up')->where(['up.if_reward'=>array('neq',1)])->join('__USER__ u on u.id=up.user_id')->field('u.username,up.*')->select();
        include template('/user/home/index');
    }
    //我的推广页面
    public function invite()
    {   
        $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,invite_code')->find();
        include template('/user/home/invite');
    }

    //我的团队页面
    public function team()
    {   
        $list = M('user')->where(['id'=>$this->id])->field('id,username,one,two,three')->find();
        $one_money = 0;
        $two_moeny = 0;
        $three_money = 0;
        if($list['one'] == '') {
            $one_list = array();
        }else{
            $one_list = array();
            $array_one = explode(',',$list['one']);
            $one_len = count($array_one);
            unset($array_one[0]);
            unset($array_one[$one_len-1]);
            
            foreach($array_one as $key=> $value){
                // var_dump($value);
                $user_info = M('user')->where(['id'=>$value])->field('id,username,nickname,real_name,register_time')->find();
                
                $one_list[$key]['real_name'] = $user_info['real_name'] ? $user_info['real_name'] : $user_info['nickname'];
                $one_list[$key]['time'] = $user_info['register_time'];

                //邀请获奖
                $one_money += M('fenhong_records')->where(['user_id'=>$value,'type'=>1])->find()['balance'];

            }
           
        }
        
        if($list['two'] == ''){
            $two_list = array();
        }else{
            $two_list = array();
            $array_two = explode(',',$list['two']);
            $two_len = count($array_two);
            unset($array_two[0]);
            unset($array_two[$two_len-1]);
            foreach($array_two as $key=> $value){
                // var_dump($value);
                $user_info = M('user')->where(['id'=>$value])->field('id,username,nickname,real_name,register_time')->find();
                $one_two_listlist[$key]['real_name'] = $user_info['real_name'] ? $user_info['real_name'] : $user_info['nickname'];
                $two_list[$key]['time'] = $user_info['register_time'];
                $two_money += M('fenhong_records')->where(['user_id'=>$value,'type'=>1])->find()['balance'];

            }
        }
        if($list['three'] == ''){
            $three_list = array();
        }else{
            $three_list = array();
            $array_three = explode(',',$list['three']);
            $three_len = count($array_three);
            unset($array_three[0]);
            unset($array_three[$three_len-1]);
            foreach($array_three as $key=> $value){
              
                $user_info = M('user')->where(['id'=>$value])->field('id,username,nickname,real_name,register_time')->find();
                $three_list[$key]['real_name'] = $user_info['real_name'] ? $user_info['real_name'] : $user_info['nickname'];
                $three_list[$key]['time'] = $user_info['register_time'];
                $three_money += M('fenhong_records')->where(['user_id'=>$value,'type'=>1])->find()['balance'];
            }
        }
        // die;
        include template('/user/home/team');
    }

    //我的钱包首页
    public function wallet_index()
    {   
        $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,nickname,upvaluation,balance,alipay_account,alipay_qr_code')->find();
        $bank_info = M('bank')->where(['user_id'=>$this->id,'status'=>1])->find();
        // var_dump($bank_info);die;
        include template('/user/home/wallet_index');
    }

    //银行卡页面
    public function bank_info(){
        $bank_info = M('bank')->where(['user_id'=>$this->id,'status'=>1])->find();
        // var_dump($bank_info);die;
        include template('/user/home/bank_info');
    }
    //添加银行卡
    public function add_bank()
    {   
        if(IS_POST){
            $param = I('post.');
            if(!$param['bank_number'] || !$param['bank_type']) showmessage('请填写完整的银行卡信息');
            $param['user_id']= $this->id;
            $param['add_time'] = date('Y-m-d H:i:s');
            $param['status'] = 1;
            try{
                $find = M('bank')->where(['user_id'=>$this->id,'status'=>1])->find();
                if($find){
                    M('bank')->where(['user_id'=>$this->id,'status'=>1])->setField('status',2);

                }
                M('bank')->add($param);
            }catch(\Exception $e){
                shomessage($e->getMessage());
            }
            showmessage('添加成功','goback',1);
        }else{
            include template('/user/home/add_bank');
        }
       
    }
    //解除银行卡
    public function remove_bank(){
        $password = trim($_POST['password']);
        // var_dump($password);
        $bank_id = $_POST['bank_id'];
        $user_info =M('user')->where(['id'=>$this->id])->field('id,username,real_name,nickname,salt,pay_password')->find();
        // var_dump($user_info);
        if(md5($user_info['salt'].$password) != $user_info['pay_password']) showmessage('交易密码不正确');
        try{
            M('bank')->where(['id'=>$bank_id])->setField('status',3);
        }catch(\Exception $e){
            showmessage($e->getMessage());
        }
        showmessage('解除成功','goback',1);
    }

    //绑定支付宝
    public function add_alipay(){
        if(IS_POST){
            $alipay_account = trim($_POST['alipay_account']);
            //判定是否有在交易中的账号
            $find = M('hang_buy')->where(array('user_id|sell_id'=>$this->id,'status'=>array('neq',4)))->find();
            if($find){
                showmessage('您有交易中的GF，不可更改个人信息');
            }
            try{
                M('user')->where(array('id'=>$this->id))->setField('alipay_account',$alipay_account);
            }catch(\Exception $e){
                showmessage($e->getMessage());
            }
            showmessage('操作成功','goback',1);
        }else{
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,nickname,alipay_account,alipay_qr_code')->find();
            include template('/user/home/add_alipay');
        }
    }
    //操作升值链页面
    public function upvaluation(){
        $upvation = M('user')->where(['id'=>$this->id])->field('id,username,upvaluation')->find()['upvaluation'];
        $bank_info = M('bank')->where(['user_id'=>$this->id])->find();
        include template('/user/home/upvaluation');
    }
    //个人信息页面
    public function personal_info()
    {   
        $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,nickname,photo,mobile_phone,wx_account')->find();
       
        include template('/user/home/personal_info');
    }

    //更改手机页面
    public function change_mobile()
    {
        if(IS_POST){
            $mobile_phone = trim($_POST['mobile_phone']);
            $find = M('hang_buy')->where(array('user_id|sell_id'=>$this->id,'status'=>array('neq',4)))->find();
            if($find){
                showmessage('您有交易中的GF，不可更改个人信息');
            }
            try{
                M('user')->where(['id'=>$this->id])->setField('mobile_phone',$mobile_phone);
            }catch(\Exception $e){
                showmessage($e->getMessage());
            }
            showmessage('操作成功','goback',1);
          
        }else{
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,mobile_phone')->find();
            include template('/user/home/change_mobile');
        }
    }
    //更改微信账号
    public function change_wx()
    {
        if(IS_POST){
            $wx_account = trim($_POST['wx_account']);
            //判定是否有在交易中的账号
            $find = M('hang_buy')->where(array('user_id|sell_id'=>$this->id,'status'=>array('neq',4)))->find();
            if($find){
                showmessage('您有交易中的GF，不可更改个人信息');
            }
            try{
                M('user')->where(array('id'=>$this->id))->setField('wx_account',$wx_account);
            }catch(\Exception $e){
                showmessage($e->getMessage());
            }
            showmessage('操作成功','goback',1);
        }else{
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,wx_account,wx_qr_code')->find();
            include template('/user/home/change_wx');
        }
    }

    //身份认证 (上传身份证)
    public function upload_identity()
    {   
        $username = isset($_GET['username']) ? $_GET['username'] : '';
        if($this->id){
            
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,nickname,if_identification,identidy_number,identity_front,identity_side')->find();
            
        }else{
            $user_info = [
                'identity_front'=> '',
                'identity_side'=> '',
            ];
        }
       
        include template('user/home/upload_identity');
    }


    public function check_if_renzheng(){
        $user_info = M('user')->where(['id'=>$this->id])->field('id,username,real_name,nickname,if_identification,identidy_number,identity_front,identity_side,identification_remarks')->find();
        if($user_info['if_identification'] == 3){
            include template('user/home/renzheng_success');
            return;
        }elseif($user_info['if_identification'] == 2){
            include template('user/home/renzheng_dengdai');
            return;
        }elseif($user_info['if_identification'] == 4){
            include template('user/home/renzheng_fail');
            return;
        }elseif($user_info['if_identification'] == 1){
            include template('user/home/upload_identity');
            return;
        }
    }

    //身份认证 （真实姓名，身份证号码）
    public function check_identity()
    {   
        $user_info = M('user')->where(['id'=>$this->id])->field('id,username,rela_name,nickname,photo,identidy_number')->find();
        if(IS_POST){

        }else{
            include template('/user/home/check_identity');
        }
    }

    //修改登录密码和交易密码
    public function upd_password()
    {
        include template('/user/home/upd_password');
    }
    //修改登录密码
    public function upd_login_password()
    {
        if(IS_POST){

        }else{
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,mobile_phone')->find();
            include template('/user/home/upd_login_password');
        }
    }
    //修改交易密码
    public function upd_trade_password()
    {
        if(IS_POST){
            $param = I('post.');
			
			if(empty($param['sms_code']) || empty($param['username']) || empty($param['password'])) showmessage('短信验证码，手机号，新密码都不能为空');
			// if(!is_mobile($param['username'])) showmessage('请填写正确格式的手机号');
			if(session('reg_code_time')+ 120 < time()) showmessage('短信验证码已经过期');
			// var_dump($param['sms_code']);
			// var_dump(session('reg_code'));
			// var_dump($param['username']);
			// var_dump(session('mobile'));
			// die;
			if($param['sms_code'] != session('reg_code')  || $param['username'] != session('mobile')) showmessage('手机号跟验证码不匹配');
			
			session("reg_code",null);
			session('username',NULL);
			//只要发送过验证码就证明该账号已经注册过并且没有被封
			// $find = M('user')->where(['username'=>$param['username']])->find();
			// if(!$find) error(['msg'=>'该手机号还没有注册']);
			$find = M('user')->where(['username'=>$param['username']])->field('id,username,salt')->find();
			if(!$find) showmessage('该手机号还没有注册');
			try{
				M('user')->where(['username'=>$param['username']])->save(['pay_password'=>md5($find['salt'].$param['password'])]);
				session('send_code_time',NULL);
			}catch(\Exception $e){
				showmessage($e->getMessage());
			}
			showmessage('修改密码成功','goback',1);
        }else{
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,mobile_phone')->find();
            include template('/user/home/upd_trade_password');
        }
    }

    //帮助中心
    public function help()
    {   
        $info = M('article')->where(['category_id'=>10,'status'=>1])->order('top desc')->select();
        include template('/user/home/help');
    }

    //关于我们
    public function about_us()
    {   
        $info = M('article')->where(['category_id'=>9,'status'=>1])->order('top desc')->select();
        include template('/user/home/about_us');
    }


    //公告
    public function notice()
    {   $info = M('article')->where(['category_id'=>7,'status'=>1])->order('top desc')->select();
        include template('/user/home/notice');
    }

    //兑换升值链
    public function exchange_upvaluation(){
        if(IS_POST){
            $number = trim($_POST['number']);
            $password = $_POST['password'];
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,salt,pay_password,balance,upvaluation')->find();
            if($user_info['balance']*2 < $number)shomessage('您的余额不足，请充值');
            if(md5($user_info['salt'].$password) != $user_info['pay_password']) showmessage('交易密码不正确');
            try{
                $data = [
                    'balance'=>($user_info['balance'] - 2*$number) ?  ($user_info['balance'] - 2*$number) : 0,
                    'upvaluation'=>$user_info['upvaluation'] + $number,
                ];
                $add = [
                    'user_id'=>$this->id,
                    'balance'=>$number,
                    'type'=>2,
                    'remarks'=>'余额兑换',
                    'add_time'=>date('Y-m-d H:i:s')
                ];
                $add1 = [
                    'user_id'=>$this->id,
                    'balance'=>-2*$number,
                    'type'=>2,
                    'remarks'=>'兑换',
                    'add_time'=>date('Y-m-d H:i:s')
                ];
                M()->startTrans();
                M('user')->where(['id'=>$this->id])->save($data);
                M('upvaluation_exchange_records')->add($add);
                M('balance_exchange_records')->add($add1);
                M()->commit();
            }catch(\Exception $e){
                M()->rollback();
                shomessage($e->getMessage());
            }
            showmessage('操作成功','goback',1);

        }else{
            showmessage('非法访问');
        }
    }

    // private function digui_team($id,$level)
    // {   
        
    //     static $list = array();
    //     if($level < 3){
    //         $select = M('user')->where(['refer_id'=>$id])->field('id,refer_id,username,real_name')->select();
    //         if($select){
    //             // var_dump($select);
    //             p($list);
    //             $list = array_merge($list,$select);
    //             foreach($select as $key => $value){
    //                 $list[$key]['level'] = $level;
    //                 // var_dump($list);
    //                 $level ++;
    //                 return $this->digui_team($value['id'],$level);
    //             }
    //         }
    //     }
    //     return $list;
    // }


    public function img_upload()
    {
        $param = I('post.');
        if($param['username'] != ''){
            // echo 1;
            $data = [
                'identity_front'=>$param['identity_front'],
                'identity_side'=>$param['identity_side'],
                // 'if_identification'=>2,
            ];
            $result = M('user')->where(['username'=>$param['username']])->save($data);
        }else{
            // echo 2;
            $data = [
                'identity_front'=>$param['identity_front'],
                'identity_side'=>$param['identity_side'],
                // 'if_identification'=>2
            ];
            $result = M('user')->where(['id'=>$this->id])->save($data);
        }
        
        // $result = M('user')->save($data);
        if($result){
            // echo 3;
            showmessage('操作成功','goback',1);
        }else{
            showmessage('操作失败');
        }

    }

    public function sure_info()
    {   
        $username = isset($_GET['username']) ? $_GET['username'] : '';
        if(IS_POST){
            $param = I('post.');
            // var_dump($param);
            if(!$param['identidy_number'] || !$param['real_name']) showmessage('请填写信息');
            $data = [
                'identidy_number'=>$param['identidy_number'],
                'real_name'=>$param['real_name'],
                'if_identification'=>2,
            ];
            if($param['username'] != ''){
                // echo 1;
                $result = M('user')->where(['username'=>$param['username']])->save($data);
            }else{
                // echo 2;
                $result = M('user')->where(['id'=>$this->id])->save($data);
            }
            
            if($result){
                showmessage('操作成功','goback',1);
            }else{
                showmessage('操作失败');
            }
        }else{
            $user_info = M('user')->where(['id'=>$this->id])->find();
            include template('/user/home/sure_info');
        }
    }
    public function renzheng_shenhe()
    {
        include template('/user/home/renzheng_shenhe');
    }

    //充值页面
    public function chongzhi()
    {   
        $bank_info = M('bank')->where(['user_id'=>$this->id,'status'=>['neq',3]])->order('status asc')->select();
        include template('/user/home/chongzhi');
       
    }

    public function check_chongzhi(){
        if(IS_POST){
            $param = I('post.');
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,salt,pay_password')->find();
            $min = C('site_balance_min');
            if($param['price'] < $min) showmessage('充值金额不能小于'.$min);
            if(md5($user_info['salt'].$param['password']) != $user_info['pay_password']) showmessage('交易密码不正确');
            //生成订单
            $data = [
                'user_id'=>$this->id,
                'balance'=>$param['price'],
                'order_number'=>$this->id.time(),
                'add_time'=>date('Y-m-d H:i:s'),
                'update_time'=>date('Y-m-d H:i:s'),
                'type'=>1,
                'status'=>1,
                'bank_number'=>M('bank')->where(['id'=>$param['id']])->find()['bank_number'],
            ];
            try{
                M('money_records')->add($data);
            }catch(\Exception $e){
                showmessge($e->getMessge());
            }
            showmessage('操作成功','goback',1);
        }else{
            showmessge('非法访问');
        }
    }


    //提现
    public function tixian(){
        $user_info = M('user')->where(['id'=>$this->id])->field('id,username,salt,pay_password,balance,if_identification,real_name,alipay_qr_code,alipay_account')->find();
        $percent = C('site_tixian_fee');
        if(IS_POST){
            $param = I('post.');
            // var_dump($param);die;
            $min = C('site_balance_min');
            if($user_info['if_identification'] != 3)showmessage('您还没有实名认证，请先实名认证');
            if($param['price'] < $min) showmessage('提现金额不能小于'.$min);
           
            // $need_have = $param['price']*(1+$percent/100);
            if($user_info['balance'] < $param['price']) showmessage('您的余额不足'.$param['price']);
            if(md5($user_info['salt'].$param['password']) != $user_info['pay_password']) showmessage('交易密码不正确');
            $data = array();
            if($param['bank'] == 1){


                if($user_info['alipay_account'] == '' ||$user_info['alipay_qr_code'] == '' ) showmessage('您还没有设定您的支付宝账号跟二维码');
                
                $account = $user_info['alipay_account'];
               
                $img = $user_info['alipay_qr_code'];
                $bank_type = '';
                
                //支付宝
                
            }else{
                $find_bank = M('bank')->where(['user_id'=>$this->id,'status'=>1])->find();
                if(!$find_bank) showmessage('您还没有设定银行卡');
                $account = $find_bank['bank_number'];
                $bank_type = $find_bank['bank_type'];
                $img = '';
            }
            $money = $param['price']*(1-$percent/100);
            //生成订单
            $data = [
                'user_id'=>$this->id,
                'balance'=>$money,
                'percent'=>$percent,
                'order_number'=>$this->tixian_order_number(),
                'add_time'=>date('Y-m-d H:i:s'),
                'update_time'=>date('Y-m-d H:i:s'),
                'type'=>$param['bank'],
                'status'=>1,
                'need_pay'=>$param['price'],
                'real_name'=>$user_info['real_name'],
                'account'=>$account,
                'img'=>$img,
                'bank_type'=>$bank_type,
                'cha'=>$param['price']-$money,
            ];

            //余额记录
            $data1 = [
                'user_id'=>$this->id,
                'balance'=>-$param['price'],
                'type'=>2,
                'remarks'=>'发起提现',
                'add_time'=>date('Y-m-d H:i:s')
            ];
            try{
                M()->startTrans();
                // M('money_records')->add($data);
                $data2 = [
                    'balance'=>$user_info['balance']- $param['price'],
                    'freeze_balance'=>$user_info['freeze_balance'] +  $param['price']
                ];
                M('tixian_records')->add($data);
                M('user')->where(['id'=>$this->id])->save($data2);
                M('balance_exchange_records')->add($data1);
                M()->commit();
            }catch(\Exception $e){
                M()->rollback();
                showmessge($e->getMessge());
            }
            showmessage('操作成功','goback',1);
        }else{
            // $bank_info = M('bank')->where(['user_id'=>$this->id,'status'=>['neq',3]])->order('status asc')->select();
         
            include template('/user/home/tixian');
        }
    }




    public function huishou(){
        
        if(IS_POST){
            $user_info = M('user')->where(['id'=>$this->id])->field('id,username,salt,pay_password,balance,if_identification,real_name,alipay_qr_code,alipay_account,upvaluation,freeze_upvaluation')->find();
            $param = I('post.');
            $percent = C('site_upvaluation_percent');
            // var_dump($param);die;
            $min = C('site_balance_min');
            if($user_info['if_identification'] != 3)showmessage('您还没有实名认证，请先实名认证');
            if($param['price'] < $min) showmessage('回收金额不能小于'.$min);
           
            // $need_have = $param['price']*(1+$percent/100);
            if($user_info['upvaluation'] < $need_have) showmessage('您的GF不足'.$param['price']);
            if(md5($user_info['salt'].$param['password']) != $user_info['pay_password']) showmessage('交易密码不正确');
            $data = array();
            if($param['bank'] == 1){


                if($user_info['alipay_account'] == '' ||$user_info['alipay_qr_code'] == '' ) showmessage('您还没有设定您的支付宝账号跟二维码');
                
                $account = $user_info['alipay_account'];
               
                $img = $user_info['alipay_qr_code'];
                $bank_type = '';
                
                //支付宝
                
            }else{
                $find_bank = M('bank')->where(['user_id'=>$this->id,'status'=>1])->find();
                if(!$find_bank) showmessage('您还没有设定银行卡');
                $account = $find_bank['bank_number'];
                $bank_type = $find_bank['bank_type'];
                $img = '';
            }
            $money = $param['price']*(1-$percent/100);
            //生成订单
            $data = [
                'user_id'=>$this->id,
                'balance'=>$money,
                'percent'=>$percent,
                'order_number'=>$this->huishou_order_number(),
                'add_time'=>date('Y-m-d H:i:s'),
                'update_time'=>date('Y-m-d H:i:s'),
                'type'=>$param['bank'],
                'status'=>1,
                'need_pay'=>$param['price'],
                'real_name'=>$user_info['real_name'],
                'account'=>$account,
                'img'=>$img,
                'bank_type'=>$bank_type,
                'cha'=>$param['price'] - $money,
            ];

            //余额记录
            $data1 = [
                'user_id'=>$this->id,
                'balance'=>-$param['price'],
                'type'=>1,
                'remarks'=>'发起回收',
                'add_time'=>date('Y-m-d H:i:s')
            ];
            try{
                M()->startTrans();
                // M('money_records')->add($data);
                $data2 = [
                    'upvaluation'=>$user_info['upvaluation']- $param['price'],
                    'freeze_upvaluation'=>$user_info['freeze_upvaluation'] +  $param['price']
                ];
                M('huishou_records')->add($data);
                M('user')->where(['id'=>$this->id])->save($data2);
                M('upvaluation_exchange_records')->add($data1);
                M()->commit();
            }catch(\Exception $e){
                M()->rollback();
                showmessge($e->getMessge());
            }
            showmessage('操作成功','goback',1);
        }else{
            showmessge('非法访问');
        }
    }


    public function balance_records()
    {   

        $records = M('balance_exchange_records')->where(['user_id'=>$this->id])->order('id desc')->select();
        include template('/user/home/balance_records');
    }

    public function upvaluation_records()
    {   
        $records = M('upvaluation_exchange_records')->where(['user_id'=>$this->id])->order('id desc')->select();
        include template('/user/home/upvaluation_records');
    }

    public function upvaluation1(){
        $user_info = M('user')->where(['user_id'=>$this->id])->find();
        $percent = C('site_upvaluation_percent');
        include template('/user/home/upvaluation2');
        
        
    }

    public function chongzhi1(){
        $type = $_GET['type'];
        $price = $_GET['price'];
        $data = [
            'user_id'=>$this->id,
            'order_number'=>$this->chong_order_number(),
            'status'=>1,
            'balance'=>$price,
            'add_time'=>date('Y-m-d H:i:s'),
            'update_time'=>date('Y-m-d H:i:s'),
            'type'=>$type
        ];

        
        $id =  M('chongzhi_records')->add($data);
       $info = M('chongzhi_records')->where(['id'=>$id])->find();
        if($type == 1){
            include template('/user/home/alipays');
            die;
        }else{
            $bank_info = C('site_bank');
            $bank_number = substr($bank_info,strripos($bank_info,'银行卡号:'));
            // var_dump($bank_number);
            $man = substr($bank_info,strpos($bank_info,'收款人:'),(strpos($bank_info,'银行卡号:')-strpos($bank_info,'收款人:')));

            // $bank_number = 
            include template('/user/home/bank_pay');
            die;
        }

    }


   public function chong_order_number(){
    $number = time().mt_rand(10000,99999);
      $find =  M('ybk_chongzhi_records')->where(['order_numberr'=>$number])->find();
      if($find){
        return $this->chong_order_number();
      }
      return $number;

   }

   public function add_alipay2(){
        $id = $_POST['id'];
        $img = M('chongzhi_records')->where(['id'=>$id])->find()['img'];
        if($img == ''){
            showmessage('请上传支付凭证');
        }
        $result = M('chongzhi_records')->where(['id'=>$id])->setField('status',2);
        if(!$result){
             showmessage('操作失败');
        }
        showmessage('操作成功,等待后台审核','goback',1);
   }


   public function tixian_order_number(){
    $number = time().mt_rand(10000,99999);
      $find =  M('ybk_tixian_records')->where(['order_numberr'=>$number])->find();
      if($find){
        return $this->chong_order_number();
      }
      return $number;

   }

   public function huishou_order_number(){
    $number = time().mt_rand(10000,99999);
      $find =  M('huishou_records')->where(['order_numberr'=>$number])->find();
      if($find){
        return $this->chong_order_number();
      }
      return $number;

   }

   //帮助中心详情
   public function help_detail(){
       $id = $_GET['id'];
    //    var_dump($id);die;
       $info = M('article')->where(['id'=>$id])->find();
    include template('/user/home/help_detail');
   }

   public function about_us_detail(){
    $id = $_GET['id'];
    //    var_dump($id);die;
       $info = M('article')->where(['id'=>$id])->find();
    include template('/user/home/about_us_detail');
   }

   public function system_detail(){
    $id = $_GET['id'];
    //    var_dump($id);die;
       $info = M('article')->where(['id'=>$id])->find();
    include template('/user/home/system_detail');
   }
}